#pragma once
#include <Windows.h>
#include <ltbasedefs.h>
#include <ltengineobjects.h>
#include <ltobjectcreate.h>
#include "CommonUtilities.h"
#include "automessage.h"
//#include "DebugTools.h"
#include "msgids.h"


#define CREATEOBJECT(val,param)  ( val##::__CreateObject((void*)(param)))
#define S_CREATEOBJECT(val,param)  (dynamic_cast<param*>(s_CreateObject(val,#param)))

#define DEG2RAD(x)		(((x)*MATH_PI)/180.0f)
#define RAD2DEG(x)		(((x)*180.0f)/MATH_PI)


inline void s_GetObjectRot(HOBJECT obj,LTRotation& rRot)
{
	g_pLTServer->GetObjectRotation(obj,&rRot);
}

inline void s_GetObjectPos(HOBJECT obj,LTVector& vPos)
{
	g_pLTServer->GetObjectPos(obj,&vPos);
}

inline float s_GetObjectX(HOBJECT obj)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	return vPos.x;
}

inline float s_GetObjectY(HOBJECT obj)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	return vPos.y;
}

inline float s_GetObjectZ(HOBJECT obj)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	return vPos.z;
}

inline void s_SetObjectPos(HOBJECT obj,const LTVector& vPos)
{
	g_pLTServer->SetObjectPos(obj,&vPos);
}

inline void s_SetObjectRot(HOBJECT obj,const LTRotation& rRot)
{
	g_pLTServer->SetObjectRotation(obj,&rRot);
}

inline void s_SetObjectX(HOBJECT obj,float x)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector( x,vPos.y,vPos.z));
}

inline void s_SetObjectY(HOBJECT obj,float y)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector(vPos.x, y,vPos.z));
}

inline void s_SetObjectZ(HOBJECT obj,float z)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector(vPos.x,vPos.y, z));
}

inline void s_SetObjectDeltaX(HOBJECT obj,float delta_x)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector(vPos.x + delta_x,vPos.y,vPos.z));
}

inline void s_SetObjectDeltaY(HOBJECT obj,float delta_y)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector(vPos.x,vPos.y + delta_y,vPos.z));
}

inline void s_SetObjectDeltaZ(HOBJECT obj,float delta_z)
{
	LTVector vPos;
	s_GetObjectPos(obj,vPos);
	s_SetObjectPos(obj,LTVector(vPos.x,vPos.y,vPos.z + delta_z));
}

extern HOBJECT GetObjectByName(const char *pName);
extern bool GetPointPos(const char* pPointName,LTVector& vOutPos);
extern bool GetPointRot(const char* pPointName,LTRotation& rOutRot);
extern bool GetPointPosAndRot(const char* pPointName,LTVector& vOutPos,LTRotation& rOutRot);
extern void CreateAttachmentObject(HOBJECT &hObj, const char* sFilename, const char* sTexture);
extern void CreateAttachmentObjectWithRenderStyle(HOBJECT &hObj, const char* sFilename, const char* sTexture,const char* RenderStyle);
extern void CreateAttachment(HATTACHMENT &hAttachment,HOBJECT hFatherObject,HOBJECT hChildObject,const char* sSocket,LTVector &vRotOffset = LTVector(0,0,0),LTVector &vPosOffset = LTVector(0,0,0));
extern LPBASECLASS s_CreateObject(ObjectCreateStruct& ocs,const char* pName);
extern LTFLOAT GetFrameTime();

